﻿<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
	<meta http-equiv="Cache-Control" content="no-siteapp"/>
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/static/html5shiv.js"></script>
	<script type="text/javascript" src="/static/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="/static/bootstrap/3.3.7/css/bootstrap.min.css"/>
	<link rel="stylesheet" type="text/css" href="/static/bootstrap-table/1.12.1/css/bootstrap-table.min.css"/>
	<link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css"/>
	<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css"/>
	<link rel="stylesheet" type="text/css" href="/static/Hui-iconfont/1.0.8/iconfont.css"/>
	<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin"/>
	<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css"/>
	<!--[if IE 6]>
	<script type="text/javascript" src="/static/DD_belatedPNG_0.0.8a-min.js"></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>定时任务管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 定时任务管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
	<div class="text-c" id="query">
		用户名：
		<input type="text" name="role" id="role" placeholder="用户名" style="width:250px" class="input-text">
		<button id="search" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a class="btn btn-primary radius" data-title="添加任务" data-href="/role/add" onclick="add('添加任务', '')" href="javascript:;">
				<i class="Hui-iconfont">&#xe600;</i> 添加任务
			</a>
		</span>
	</div>
	<div class="mt-20">
		<table id="table" >
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/bootstrap-table/1.12.1/js/bootstrap-table.min.js"></script>
<script type="text/javascript" src="/static/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript">
	var url = '/job/list';
	var offset = 1;
    $(document).ready(function () {
        $('#table').bootstrapTable({
            url: url,
            method: 'post',
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: true,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 5,                       //每页的记录行数（*）
            pageList: [5, 10, 20, 50],        //可供选择的每页的行数（*）
            strictSearch: true,
            clickToSelect: true,                //是否启用点击选中行
            uniqueId: "id",                     //每一行的唯一标识，一般为主键列
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            contentType: "application/x-www-form-urlencoded",
            queryParamsType: '',
            queryParams: queryParams,
            columns: [
                {
                    field : 'checked',
                    checkbox : true,
                    align: 'center',
                    width: '3%'
                },{
                    title: '序号',
                    width: '4%',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return offset + index + 1;
                    }
                }, {
					field: 'jobName',
					title: '任务名称',
					width: 50
				}, {
					field: 'jobGroup',
					title: '任务分组',
					width: 100
				}, {
                    field: 'description',
                    title: '任务描述',
                    width: 100
                }, {
                    field: 'className',
                    title: '执行类',
                    width: 100
                }, {
                    field: 'cron',
                    title: 'cron',
                    width: 100
                }, {
                    field: 'tiggerTime',
                    title: '执行时间',
                    width: 100
                }, {
                    field: 'state',
                    title: '状态',
                    width: 100,
					formatter: function (value, row, index) {
						if(value == '00') {
						    return '正在运行';
						}
						if(value == '10') {
							return '已停止';
						}
						if(value == '20') {

						}
                    }
                }, {
					field: 'id',
					title: '操作',
                    width: 100,
					formatter: function (value, row, index) {
                        return '<a title="触发任务" href="javascript:;" onclick="task(\'tigger\', \'' + value + '\')" class="btn btn-secondary size-MINI radius" style="text-decoration:none"><i class="Hui-iconfont">&#xe614;</i></a>	' +
                            '<a title="停止任务" href="javascript:;" onclick="task(\'pause\', \'' + value + '\')" class="btn btn-warning size-MINI radius" style="text-decoration:none"><i class="Hui-iconfont">&#xe706;</i></a>	' +
                            '<a title="恢复任务" href="javascript:;" onclick="task(\'resume\', \'' + value + '\')" class="btn btn-success size-MINI radius" style="text-decoration:none"><i class="Hui-iconfont">&#xe606;</i></a>	' +
							'<a title="编辑" href="javascript:;" onclick="add(\'修改任务\',\'' + value + '\')" class="btn btn-primary size-MINI radius" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>  ' +
                            '<a title="删除" href="javascript:;" onclick="del(\'' + value + '\')" class="btn btn-danger size-MINI radius" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
					}
				}
            ]
        });
        
        $('#search').click(function () {
            refresh();
        });
    });

    function queryParams(params) {
        params.s = {};
        $('#query').find('*[name]').each(function() {
            var value = $.trim($(this).val());
            var name = $.trim($(this).attr('name'));
            if(name && value){
                params.s[$(this).attr('name')] = value;
            }
        });
        offset = params.pageSize * (params.pageNumber - 1);
        return params;
	}

	//任务新增
	function add(title, id) {
        layer_show(title, '/job/add?id='+id, '', 400);
	}

    //任务操作
    function task(obj, id) {
        $.ajax({
            type: 'POST',
            url: '/job/' + obj,
            data: {'id': id},
            dataType: 'json',
            success: function (data) {
                if(data.success) {
                    layer.msg(data.descr, {icon: 1, time: 1000});
                    refresh();
                } else {
                    layer.msg(data.descr, {icon: 2, time: 1000});
                }
            },
            error: function (data) {
                layer.msg("操作失败", {icon: 2, time: 1000})
            },
        });
    }

	//角色删除
    function del(id) {
        layer.confirm('任务删除须谨慎，确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: '/job/delete',
                data: {'id': id},
                dataType: 'json',
                success: function (data) {
                    if(data.success) {
                        layer.msg(data.descr, {icon: 1, time: 1000});
                        refresh();
					} else {
                        layer.msg(data.descr, {icon: 2, time: 1000});
					}
                },
                error: function (data) {
                    layer.msg("删除失败", {icon: 2, time: 1000})
                },
            });
        });
    }

	function refresh() {
        $('#table').bootstrapTable('refresh', {url: url});
    }
</script>
</body>
</html>